<template>
  <!--课程购买-->
  <div>
    <headers></headers>
    <div class="padding88">
      <div class="divider">
        <div class="auto">
          <router-link to="/">首页</router-link><span>></span><span >线下课程列表</span>
        </div>
      </div>
    </div>
    <div v-if="courses.length !== undefined && courses.length > 0" class="padding250" >
      <div class="auto padding250">
        <course :courses="courses" :online="0"></course>
      </div>
     <div class="pageout"><Page :total="total" :current="pageNumber" :page-size="size" @on-change="changePage"/></div>
    </div>
    <div v-else >
      <nodata tip="暂时还没有课程哦~"></nodata>
    </div>
    <Spin fix v-show="isSpinShow" >
      <div class="loader">
        <Icon type="ios-loading" size=26 class="demo-spin-icon-load"></Icon>
        <div class="font14">加载中...</div>
      </div>
    </Spin>
    <footers></footers>
  </div>
</template>
<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped lang="less" rel="stylesheet/less">
  /* 旋转效果 */
  .demo-spin-icon-load{
    animation: ani-demo-spin 1s linear infinite;
  }
  @keyframes ani-demo-spin {
    from { transform: rotate(0deg);}
    50% { transform: rotate(180deg);}
    to { transform: rotate(360deg);}
  }
  /* 假如内容过长，一屏放不下，滚动条下拉覆盖不全 */
  .ivu-spin-fix {
    position: fixed;
  }

  .divider{
    height: 60px;
    background-color: #2F261E;
    font-size: 14px;
    line-height: 60px;
    text-align: left;
    color: #fff;
    span{
      margin: 0 10px;
    }
    a{
      color: #fff;
      &:hover{
        color: #9C7649;
        font-weight: 700;
      }
    }
  }
  .title{
    font-size: 26px;
    color: #000;
    padding: 15px;
    text-align: left;
    li{
      display: inline-block;
      margin-right: 30px;
      a{
        padding: 10px;
        font-size: 14px;
        color: #333;
      }
    }
    li.active {
      a{
        font-weight: 700;
        color: #957960;
        border-bottom: 3px solid #957960;
      }
    }
    li:last-child{
      margin-right: 0;
    }
  }
</style>
<script type="text/ecmascript-6">
  import course from '../template/course'
  import headers from '../template/header'
  import footers from '../template/footer'
  import nodata from '../template/null'
  import {centreInfoWeb, offlineCourseListWeb} from '../../http'
  import {getStore} from "../../storage";
  export default {
    name: 'list',
    props: {},
    data() {
      return {
        courses:'',         //课程列表
        online:0,           //0线下 1线上
        total:0,            //总数
        size:16,            //每页课程数
        pageNumber:1,       //页数
        isSpinShow:false,
      };
    },
    methods: {
      //获取线下课程列表
      getOffCourses(){
        offlineCourseListWeb({pageNumber: this.pageNumber,pageSize:this.size}).then(res => {
          this.isSpinShow = false;
          if (res.code === 200) {
            this.courses = res.data.list.rows;
            this.total = res.data.list.total;
          }
        }).catch()
      },
      //页码切换
     changePage(pageNumber){
        this.pageNumber = pageNumber;
        //获取线下课列表
       if (this.isSpinShow === false) {
         this.isSpinShow = true;
         if (getStore('token') !== null && getStore('token') !== undefined && getStore('token') !== '') {
           //获取用户信息
           centreInfoWeb().then(res => {
             if (res.code === 200) {
               this.getOffCourses();
             } else {
               this.getOffCourses();
             }
           }).catch()
         } else {
           this.getOffCourses();
         }
       }
     },
     getOfflineCourseList() {
       //获取线下课列表
       if (this.isSpinShow === false) {
         this.isSpinShow = true;
         if (getStore('token') !== null && getStore('token') !== undefined && getStore('token') !== '') {
           //获取用户信息
           centreInfoWeb().then(res => {
             if (res.code === 200) {
               this.getOffCourses();
             } else {
               this.getOffCourses();
             }
           }).catch()
         } else {
           this.getOffCourses();
         }
       }
     }
    },
    created() {
      this.getOfflineCourseList();
    },
    components: {
      headers,
      footers,
      course,
      nodata
    }
  }
</script>
